﻿using System.Linq;
using CoreLibrary.Repo;
using Entities.DataBase.Persistent;

namespace Entities.DataBase {

    public class LogService : BaseRepository<Log>, ILogService{

        public override string TableName {
            get { return "D_LOG"; }
        }

        public void AddLog(Log log) {
            Execute((context, ts) => {
                context.GetTable<Log>().InsertOnSubmit(log);
                context.SubmitChanges();
                ts.Complete();
            });
        }

        public void RemoveLog(string logId) {
            Execute((context, ts) => {
                var l = context.GetTable<Log>().SingleOrDefault(log => log.Id.Equals(logId));
                if (l != null) {
                    context.GetTable<Log>().DeleteOnSubmit(l);
                    context.SubmitChanges();
                }
                ts.Complete();
            });
        }
    }
}